package com.dayuanit.pokergame.rule;

import com.dayuanit.pokergame.Game;
import com.dayuanit.pokergame.GameUtil;
import com.dayuanit.pokergame.Person;
import com.dayuanit.pokergame.Poker;

/**
 * 单张的比较规则
 */
public class SingleRuleEngine implements RuleEngine {

    @Override
    public void juge(Person p1, Person p2) {
        Poker[] pokers1 = p1.getPokers();
        Poker[] pokers2 = p2.getPokers();

        //当每个玩家的最大的那张牌不相等时 ，大小就已经分了

        int personMax1 = Integer.max(pokers1[0].getWeight(), pokers1[1].getWeight());
        int personMax2 = Integer.max(pokers2[0].getWeight(), pokers2[1].getWeight());

        //当玩家单张的最大值相等，则将两张牌的权重相加
        if (personMax1 == personMax2) {
            GameUtil.sum(p1, pokers1[0].getWeight() + pokers1[1].getWeight());
            GameUtil.sum(p2, pokers2[0].getWeight() + pokers2[1].getWeight());
        } else {
            //当玩家的最大的牌不相等，只给最大的那个玩家加分
            if (personMax1 > personMax2) {
                GameUtil.sum(p1, personMax1);
            } else {
                GameUtil.sum(p2, personMax2);
            }
        }
    }
}
